758B - Blown Garland - CodeForces Solution


brute force implementation number theory *1100

Please click on ads to support us..

Python Code:

import math

def _input(): return map(int, input().split())

s = input()
res = [0]*4
i=0
ss = ''
while i<len(s) and len(ss)<4:
    if s[i]!='!': ss += s[i]
    else:
        j = i+4
        while j<len(s) and s[j]=='!': j+=4
        ss+=s[j]
    i+=1

for i in range(len(s)): 
    if s[i]=='!': 
        k = ss[i%4]
        if k == 'R': res[0]+=1
        if k=='B': res[1]+=1
        if k=='Y': res[2]+=1
        if k=='G': res[3]+=1
print(*res)


        
        

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define INF 9999
#define F first
#define S second
#define pb(x)  push_back(x)
#define vi  vector<int> 
#define vstr vector<string>
#define pii  pair<int,int>
#define all(x)  (x).begin(),(x).end()
typedef long long ll;
void solve() {
    string str;
    cin>>str;
    map<int,char> m;
    for(int i=0;i<str.length();i++) {
        if(str[i] == 'G') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'R') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'Y') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        else if(str[i] == 'B'){
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            m.insert({pos,str[i]});
        }
        if(m.size() == 4) break;
    }
    map<char,int> n;
    for(int i=0;i<str.length();i++) {
        if(str[i] == '!') {
            int pos=((i+1) %4 == 0)?4:(i+1)%4;
            char col=m[pos];
            n[col]++;
        }
    }
    int ky=0,kb=0,kr=0,kg=0;
    ky=n['Y'];
    kg=n['G'];
    kb=n['B'];
    kr=n['R'];
    cout<<kr<<" "<<kb<<" "<<ky<<" "<<kg<<endl;
    return ;
}
int main() {
    solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word